package main

import "fmt"

// UserRepository 负责数据访问接口
type UserRepository interface {
	GetUserName(userID int) string
}

// UserRepositoryImpl 是 UserRepository 的具体实现
type UserRepositoryImpl struct{}

func (r *UserRepositoryImpl) GetUserName(userID int) string {
	return "Get geng UserAlice"
}

type BzRepositoryImpl struct{}

// 实现接口
func (r *BzRepositoryImpl) GetUserName(userID int) string {
	return "Get Bz User : Bob"
}

// UserService 负责业务逻辑
type UserService struct {
	repo UserRepository
}

// NewUserService 通过依赖注入传入 UserRepository
func NewUserService(repo UserRepository) *UserService {
	return &UserService{
		repo: repo,
	}
}

func (s *UserService) PrintUserName(userID int) {
	name := s.repo.GetUserName(userID)
	fmt.Println("User name is:", name)
}

func main() {
	repo := &UserRepositoryImpl{}
	service := NewUserService(repo) // 依赖注入
	service.PrintUserName(1)

	bzRepo := &BzRepositoryImpl{}
	bzService := NewUserService(bzRepo)
	bzService.PrintUserName(2)
}
